from sklearn.datasets import make_classification #自动生成分类数据集
from sklearn.metrics import classification_report#生成分类评估报告
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression#逻辑回归分类模型

#1.生成数据
X,Y = make_classification(n_samples=1000, n_features=20, n_classes=2,random_state=42)

#划分数据集
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3, random_state=42)

#3.定义一个分类模型（逻辑回归）
model = LogisticRegression()

#模型训练
model.fit(X_train, Y_train)

#5.预测（测试）
Y_pred = model.predict(X_test)

#6.生成分类评估报告
report = classification_report(Y_test, Y_pred)
print(report)

#获取预测正类的概率值
Y_pred_proba = model.predict_proba(X_test)[:,1]
#print(Y_pred_proba)

#计算AUC值
from sklearn.metrics import roc_auc_score
roc_auc = roc_auc_score(Y_test, Y_pred_proba)
print(roc_auc)

